import logging
import os

class LogCustom():

    def __init__(self,output_file=False,file=None,mode='a'):
        self.lg = logging.getLogger('myLog')
        self.lg.level = logging.INFO
        if output_file == False:
            self.myHandler = logging.StreamHandler()
        else:
            self.myHandler = logging.FileHandler(file,mode)
        self.fmt = logging.Formatter(
            fmt='%(asctime)s [%(pathname)s:%(lineno)d 行]| %(levelname)s | %(message)s',
            datefmt='%Y/%m/%d/%X')

    def debug(self,message):
        self.myHandler.setFormatter(self.fmt)
        self.lg.addHandler(self.myHandler)
        self.lg.debug(message)

    def info(self,message):
        self.myHandler.setFormatter(self.fmt)
        self.lg.addHandler(self.myHandler)
        self.lg.info(message)

    def warning(self,message):
        self.myHandler.setFormatter(self.fmt)
        self.lg.addHandler(self.myHandler)
        self.lg.warning(message)

    def error(self,message):
        self.myHandler.setFormatter(self.fmt)
        self.lg.addHandler(self.myHandler)
        self.lg.error(message)

    def critical(self,message):
        self.myHandler.setFormatter(self.fmt)
        self.lg.addHandler(self.myHandler)
        self.lg.critical(message)



# if __name__ == '__main__':
#     # print(os.path.exists('../config'))
#
#     dd = LogCustom(output_file=True,file='../log/Info.log')
#     dds = LogCustom(output_file=True, file='../log/Info1.log')
#     ss = LogCustom()
#
#     dd.debug('dasfd')
#     dds.debug('dasssafd')
#     ss.info('sssssssss')
#     ss.error('ddddddddddd')